package com.example.spring_seatreservation.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.spring_seatreservation.entity.SeminarRoomReservation;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface SeminarRoomReservationMapper extends BaseMapper<SeminarRoomReservation> {

    @Select("SELECT t.id,t.title,t.number,t.state,t.res_date,t.orderstart,t.orderend,r.name as room_name,l.name as library_name,f.name as floor_name " +
            "FROM seminar_room_reservation t " +
            "left join seminar_room r on r.id = t.room_id " +
            "left join library l on l.id = t.lib_id " +
            "left join floor f on f.id = t.floor_id " +
            "where t.reader_id = #{userId}")
    List<SeminarRoomReservation> getReservationByUser(Long userId);

    @Select("<script>" +
            "SELECT t.id,t.title,t.number,t.state,t.res_date,t.orderstart,t.orderend," +
            "r.name as room_name,l.name as library_name,f.name as floor_name,u.number as user_number,u.username as user_name " +
            "FROM seminar_room_reservation t " +
            "left join seminar_room r on r.id = t.room_id " +
            "left join library l on l.id = t.lib_id " +
            "left join floor f on f.id = t.floor_id " +
            "left join user u on u.uid = t.reader_id " +
            "where 1=1 " +
            "<if test=\"number != '' and number != null\"> and u.number = #{number} </if> " +
            "<if test=\"userName != '' and userName != null\"> and u.username like concat('%', #{userName}, '%') </if> " +
            "</script>")
    List<SeminarRoomReservation> getSemReservation(String number,String userName);
}
